//
//  ExampleTableViewController.m
//  LearnObjC
//
//  Created by czera on 2021/2/23.
//

#define kItemTitle @"title"
#define kItemClass @"class"

#define addClass(title, class) @{ \
    kItemTitle: title, \
    kItemClass: NSStringFromClass(class), \
}

#import "ExampleTableViewController.h"
#import "GYOwnerStatisticsController.h"
#import "SwiftyFitsizeViewController.h"
#import "TestViewController.h"

@interface ExampleTableViewController ()

@property (nonatomic, strong) NSArray *arrayM;

@end

@implementation ExampleTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"页面列表";
    
    self.arrayM = @[
        addClass(@"按钮连续点击", TestViewController.class),
        addClass(@"数据统计", GYOwnerStatisticsController.class),
        addClass(@"屏幕适配", SwiftyFitsizeViewController.class),
    ];
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.arrayM.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *const reuseId = @"reuseId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseId];
    }
    NSDictionary *dict = self.arrayM[indexPath.row];
    cell.textLabel.text = dict[kItemTitle];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dict = self.arrayM[indexPath.row];
    Class cls = NSClassFromString(dict[kItemClass]);
    // 如果有参数, 在这里传   NSDictionary *params = dict[@"params"];
    UIViewController *vc = [[cls alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
